package com.hh.bss.project.controller;

import static com.hh.bss.util.extjs.JsonHelper.outJson;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import com.hh.bss.auth.client.OnlineManager;
import com.hh.bss.auth.client.OnlineUser;
import com.hh.bss.base.BaseSpringController;
import com.hh.bss.common.page.Page;
import com.hh.bss.common.page.PageRequest;
import com.hh.bss.customer.entity.CompanyDeptTitle;
import com.hh.bss.project.entity.SearchProject;
import com.hh.bss.project.service.PlanService;
import com.hh.bss.project.vo.query.PlanQuery;
import com.hh.bss.util.extjs.ExtJsPageHelper;
import com.hh.bss.util.extjs.ListRange;

@Controller
public class PlanController extends BaseSpringController {
	private PlanService planService;
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	/** 通过spring自动注入 */
	public void setPlanServiceImpl(PlanService service) {
		this.planService = service;
	}	
	
	public void list(HttpServletRequest request,HttpServletResponse response,PlanQuery planQuery) throws IOException
	{
		
		OnlineManager onlineManager=super.getOnlineManager(request, response);
		if (onlineManager!=null){
				OnlineUser onlineUser=onlineManager.getOnlineUser();
				if (onlineUser!=null) {
					planQuery.setOperator(onlineUser.getUsername());
				}
			}
		
		PageRequest<Map> pr = ExtJsPageHelper.createPageRequestForExtJs(request, DEFAULT_SORT_COLUMNS);
		Page page = planService.findPlanPage(planQuery);
		
		List<SearchProject> SearchProjectlist = (List) page.getResult();
		ListRange<SearchProject> resultList = new ListRange<SearchProject>();
		resultList.setRows(SearchProjectlist);
		resultList.setTotal(page.getTotalCount());
		resultList.setMessage("ok");
		resultList.setSuccess(true);
		outJson(response,resultList);
		
	}
}
